/**
 * 
 */
package de.saar.penguin.give2.server;

import de.saar.penguin.give2.server.alert.Alert;
import java.util.*;

import give.formula.*;

/**
 * @author Johannes
 *
 */
public class Instruction implements Cloneable {

    public String instructionPhrase = "";
    //This one is needed for the room alerts
    public String customInstructionPhrase = "";
    public List<Alert> alerts;
    public Atom targetAtom;
    public boolean isAgainInstruction;
    public boolean hasBeenSent;
    // What has been the TargetType in the InstructionContainer will now be covered by the alerts.
    String targetRegion;
    String targetObjectId;
    Double targetAngle;
    Position launchedPosition;
    Orientation launchedOrientation;

    /*
     * Extend the instruction for High Level
     */
    //Is the instruction a high level one?
    private boolean highLevel = false;
    //The list of the valid high level paths for this instruction
    private HighLevelPath path;

    public Instruction(String instructionPhrase) {
        this.instructionPhrase = instructionPhrase;
        this.alerts = new ArrayList<Alert>();
        this.targetAtom = null;
    }

    public Instruction(String instructionPhrase, Atom targetAtom) {
        this.instructionPhrase = instructionPhrase;
        this.alerts = new ArrayList<Alert>();
        this.targetAtom = targetAtom; //.clone();
    }

    public Instruction(String instructionPhrase, Atom targetAtom, String targetObjectId) {
        this.instructionPhrase = instructionPhrase;
        this.alerts = new ArrayList<Alert>();
        this.targetAtom = targetAtom; //.clone();
        this.targetObjectId = targetObjectId;
    }

    public void update(String instructionPhrase, Atom targetAtom, String targetObjectId) {
        this.instructionPhrase = instructionPhrase;
        this.targetAtom = targetAtom;
        this.targetObjectId = targetObjectId;
    }

    public boolean isHighLevel() {
        return highLevel;
    }

    public HighLevelPath getPath() {
        return path;
    }

    public void setHighLevel(boolean hl) {
        this.highLevel = hl;
    }

    public void setPath(HighLevelPath path) {
        this.path = path;
    }

    public Instruction Clone() {
        Instruction instruction = new Instruction(this.instructionPhrase, this.targetAtom);
        instruction.instructionPhrase = this.instructionPhrase;
        instruction.customInstructionPhrase = this.customInstructionPhrase;

        instruction.alerts = this.alerts;
        instruction.targetAtom = this.targetAtom;
        instruction.isAgainInstruction = this.isAgainInstruction;
        instruction.hasBeenSent = this.hasBeenSent;
        instruction.setHighLevel(highLevel);
        instruction.setPath(path);

        // What has been the TargetType in the InstructionContainer will now be covered by the alerts.
        instruction.targetRegion = this.targetRegion;
        instruction.targetObjectId = this.targetObjectId;
        instruction.targetAngle = this.targetAngle;
        instruction.launchedPosition = this.launchedPosition;
        instruction.launchedOrientation = this.launchedOrientation;

        return instruction;
    }
}
